package com.study.guide.codec.MessagePack;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.LengthFieldBasedFrameDecoder;
import io.netty.handler.codec.LengthFieldPrepender;

public class TimeServerInitializer extends ChannelInitializer<SocketChannel> {

	@Override
	protected void initChannel(SocketChannel ch) throws Exception {
		ChannelPipeline pl = ch.pipeline(); //连接所有处理器
		pl
			.addLast(new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0,4,0,4))//消息长度在消息头中
			.addLast(new LengthFieldPrepender(4)) // 这就是添加4个字节的消息长度
//			.addLast(new StringDecoder(CharsetUtil.UTF_8))
//			.addLast(new StringEncoder(CharsetUtil.UTF_8))
			.addLast(new MsgpackDecoder())
			.addLast(new MsgpackEncoder())
			.addLast(new TimeServerHandler());
	}

}
